import React, { useEffect, useState } from 'react'
// 消息
import { NavBar } from 'antd-mobile'
import { useNavigate } from 'react-router-dom';
import axios from 'axios';

axios.defaults.baseURL = 'http://127.0.0.1:3000';

export default function Message() {
  const navigate = useNavigate();
  const back = () => navigate(-1);

  const [orderMes, setOrderMes] = useState([]);

  const getOrder = async () => {
    const { data: { code, order } } = await axios.get('/users/order', { params: { cate: 3 } });
    if (code === 200) {
      setOrderMes(order);
    }
  }
  useEffect(() => {
    getOrder();
  }, [])
  return (
    <div>
      <NavBar onBack={back}>系统消息</NavBar>
      <div>
        {
          orderMes.map(item => <div style={{ background:"white",width:"85%",height:"2rem",borderRadius:"0.2rem",padding:'0.15rem',margin:'0 auto',marginTop:'0.15rem'}} key={item._id}>
            <h3 style={{fontSize:'0.35rem'}}>消息通知</h3>
            <p style={{marginTop:'0.2rem'}}>您购买的{item.goodsid.map(it => <span>"{it.name}"</span>)}已发货</p>
          </div>)
        }
      </div>
    </div>
  )
}
